package com.sin.j2me.framework;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;

public class Debug {
	private static Display display = null;
	private static boolean showOnScreen = true;
	
	public static void setShowOnScreen(boolean show) {
		showOnScreen = show;
	}
	
	public static void setDisplay(Display display) {
		Debug.display = display;
	}

	static public void Error(Exception e){
		e.printStackTrace();
		Error(e.getMessage());
	}
	
	static public void Error(Error e){
		e.printStackTrace();
		Error(e.getMessage());
	}
	
	static public void Error(String err){
		Msgbox("Exception", err, AlertType.ERROR);
	}
	
	static public void Info(String info){
		Msgbox("Information", info, AlertType.INFO);
	}
	
	static public void Println(String str){
		System.out.println(str);
	}
	
	static private void Msgbox(String title, String message, AlertType type){
		System.out.println(title + ":" + message);
		
		if(showOnScreen == false)
			return;

		if(display != null){
			Alert alert = new Alert(title, message, null, type);
			alert.setTimeout(Alert.FOREVER);
			display.setCurrent(alert);
		}
	}
}
